import zmq
import time
import struct


def publisher():
    context = zmq.Context()
    socket = context.socket(zmq.PUB)
    socket.bind("tcp://localhost:5556")
    topic = b"test"

    try:
        counter = 0
        while True:
            bin_data = topic + b" Hello zmq count:"
            bin_data += struct.pack("=i", counter)
            socket.send(bin_data)
            print(f"Published: {bin_data}")
            counter += 1
            time.sleep(1)
    except KeyboardInterrupt:
        print("Publisher stopped.")
    finally:
        socket.close()
        context.term()


if __name__ == "__main__":
    publisher()
